package com.dynamicprogram;

import java.util.List;

public class Solution91 {
    public int numDecodings(String s) {
        s = " " + s;
        int[] dp = new int[s.length()];
        dp[0] = 1;
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) != '0') dp[i] = dp[i - 1];
            int c = (s.charAt(i - 1) - '0') * 10 + (s.charAt(i) - '0');
            if (c > 9 && c <= 26) dp[i] += dp[i - 2];
        }
        return dp[s.length() - 1];
    }
}
